package classDemo;

/**
 * @author Ajie
 * @date 4/16/21
 * @function 拿到方法的调用栈
 */
public class MethodGetStackTrace {
    public static void main(String[] args) {

        methodA();
    }

    private static void methodA() {
        methodB();
    }

    private static void methodB() {
        methodC();
    }

    private static void methodC() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
            StackTraceElement stackTraceElement = stackTrace[i];
            System.out.println(stackTraceElement.getClassName()+" --> "+stackTraceElement.getMethodName());

            System.out.println(stackTraceElement.toString());
        }

        System.out.println("---------");
        for (StackTraceElement stackTraceElement : stackTrace) {
            System.out.println(stackTraceElement.toString());
        }
    }
}
